# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/10/14 0014'
__author__ = 'Administrator'
__filename__ = 'sever_send'
文件注解：
文件版本：
"""

import json
import sys
import os
import time
import paho.mqtt.client as mqtt

import time

import paho.mqtt.publish as publish


def ask_ins(id):
    # msgs = [{'topic': "two/"+id, 'payload': "<<ask>>"}]
    # publish.multiple(msgs, hostname="47.105.162.90")
    client.publish("two/" + id, "<<ask>>")

def money_ins(id, pay, num):
    time_str = "rmb"+str(pay)+"num"+str(num)+"-"+time.strftime("%H:%M:%S")+"tim"
    # msgs = [{'topic': "two/"+id, 'payload': time_str}]
    client.publish("two/" + id, time_str)


def start_ins(id):
    msgs = [{'topic': "two/" + id, 'payload': "<<start>>"}]
    # publish.multiple(msgs, hostname="47.105.162.90")
    client.publish("two/" + id, "<<start>>")

def clear_ins(id):
    msgs = [{'topic': "two/" + id, 'payload': "<<clear>>"}]
    # publish.multiple(msgs, hostname="47.105.162.90")
    client.publish("two/" + id, "<<clear>>")

while True:
    client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
    client = mqtt.Client(client_id, transport='tcp')
    client.username_pw_set("zskjtest/zfpcb", "c026soJRygQTc6wat8fflf2aEbG9vyDk7Rd+90yDQSW=")
    client.connect("47.105.162.90", 1883, 60)  # 链接
    client.loop_start()

    print("please send mqtt ins")
    code = input("")
    if code == "a":
        ask_ins("4251118c0130015")
    elif code == "m":
        money_ins("4251118c0130015", 200, 50)
    elif code == "s":
        start_ins("4251118c0130015")
    elif code == "c":
        clear_ins("4251118c0130015")



